package com.qdu.average;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;
public class AverageDriver {
    public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException {
        Configuration configuration=new Configuration();
        if (args.length<2){
            System.err.println("请按照如下格式输入：\n 命令  <输入文件夹>  <输出文件夹>");
            System.exit(1);
        }
        Job job=Job.getInstance(configuration,"average");
        job.setJarByClass(AverageDriver.class);

        job.setMapperClass(AverageMapper.class);
        job.setMapOutputKeyClass(Text.class);
        job.setOutputValueClass(LongWritable.class);

        job.setReducerClass(AverageReducer.class);
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(LongWritable.class);

        FileInputFormat.addInputPath(job,new Path("hdfs://songchao:9000/data/user_learn_statistics_total"));
        FileOutputFormat.setOutputPath(job,new Path("hdfs://songchao:9000/output/average"));
        System.exit(job.waitForCompletion(true) ? 0 : 1);
    }
}
